package com.llc.station.kcp.ui.core.component;

import com.llc.station.kcp.ui.core.bean.MacCar;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;

/**
 * 作者 朱小杰
 * 时间 2017/9/12
 * 说明 待支付的车辆列表
 */
public class MacCarWaitContainer extends VBox {

    /**
     * 可以存放多少车辆列表
     */
    private int maxCarSize = 2;
    /**
     * 留给两侧的空间是多少
     */
    private int padding = 8;
    /**
     * 油品，如98 95
     */
    protected String oilType;

    public MacCarWaitContainer(String oilType) {
        this.oilType = oilType;
        init();
    }

    public MacCarWaitContainer(String oilType, double spacing) {
        super(spacing);
        this.oilType = oilType;
        init();
    }

    public MacCarWaitContainer(String oilType, Node... children) {
        super(children);
        this.oilType = oilType;
        init();
    }

    public MacCarWaitContainer(String oilType, double spacing, Node... children) {
        super(spacing, children);
        this.oilType = oilType;
        init();
    }

    public void addMacCar() {

    }

    private void init() {
        this.setAlignment(Pos.TOP_CENTER);
        this.setPadding(new Insets(0,5,5,5));
    }

    public void addWaitCar(MacCar macCar){
        if(macCar == null){
            throw new NullPointerException("车辆信息不能为空");
        }
        if (getChildren().size() >= maxCarSize){
            throw new IndexOutOfBoundsException("车辆越界，最大值为:" + maxCarSize);
        }
        MacCar.TagColor colorTag = macCar.getUniqueTag();
        BackgroundFill fill = new BackgroundFill(colorTag.getColor(),new CornerRadii(0),new Insets(0,0,0,0));
        Background background = new Background(fill);

        double width = getPrefWidth() - padding * 2;
        double height = getPrefHeight() / 3;

        WaitCarPane vBox = new WaitCarPane(macCar.getCarNumber());
        vBox.setAlignment(Pos.CENTER);
        VBox.setMargin(vBox,new Insets(5,0,0,0));
        vBox.setBackground(background);
        vBox.getStyleClass().add("waitCar");
        vBox.setPrefWidth(width);
        vBox.setPrefHeight(height);

        HBox hBox = new HBox();
        hBox.setAlignment(Pos.CENTER);
        Label carNumberLabel = new Label(macCar.getCarNumber());
        carNumberLabel.getStyleClass().add("waitCar_carNumber");
        hBox.getChildren().add(carNumberLabel);

        Label type = new Label(colorTag.getTag());
        type.setPadding(new Insets(0,8,0,8));
        HBox.setMargin(type,new Insets(0,0,0,8));
        type.getStyleClass().add("carNumberTag");
        hBox.getChildren().add(type);
        vBox.getChildren().add(hBox);


        Label payInfo = new Label(macCar.getQty() + "L   ¥" + macCar.getMoney());
        payInfo.getStyleClass().add("waitCar_payInfo");
        vBox.getChildren().add(payInfo);

        this.getChildren().add(vBox);
    }
}
